package com.example.wastes.order.controller;

import com.example.wastes.common.pojo.Order;
import com.example.wastes.common.pojo.R;
import com.example.wastes.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiOperation;

@RestController
@CrossOrigin
public class OrderController {
    @Autowired
    private OrderService orderService;

    @GetMapping("/findAllName")
    @ApiOperation("用户和订单表和员工表的关联")
    public R findAllName(){
        return new R(true, orderService.findAllName());
    }

    @GetMapping("/findOrderAddress")
    @ApiOperation("通过地址查询所有模糊查询")
    public R findOrderAddress(String address){
        return new R(true, orderService.findOrderAddress(address));
    }

    @PostMapping("/addOrder")
    @ApiOperation("添加订单表")
    public R addOrder(@RequestBody Order order){
        return new R(orderService.addOrder(order));
    }

    @PutMapping("/updateOrder")
    @ApiOperation("修改订单表")
    public R updateOrder(@RequestBody Order order){
        return new R(orderService.updateOrder(order));
    }

    @DeleteMapping("/deleteOrder/{onumber}")
    @ApiOperation("删除订单表")
    public R deleteOrder(@PathVariable String onumber){
        return new R(orderService.removeByOnumber(onumber));
    }

    @GetMapping("/getAllOrder")
    @ApiOperation("查询订单表所有")
    public R getAllOrder(){
        return new R(true, orderService.findAll());
    }
}
